package com.zhiliang.waibao.myapplication.ui.login.presenter;





import android.text.TextUtils;

import com.zhiliang.waibao.myapplication.bean.LoginBean;
import com.zhiliang.waibao.myapplication.net.BaseApi;
import com.zhiliang.waibao.myapplication.net.BaseObserver;
import com.zhiliang.waibao.myapplication.net.RxSchedulers;
import com.zhiliang.waibao.myapplication.ui.base.BasePresenter;
import com.zhiliang.waibao.myapplication.ui.login.contract.LoginContract;

import javax.inject.Inject;

public class LoginPresenter extends BasePresenter<LoginContract.View> implements LoginContract.Presenter {
    BaseApi baseApi;

    @Inject
    public LoginPresenter(BaseApi baseApi) {
        this.baseApi = baseApi;
    }

    @Override
    public void login(String tel, String password) {
        if (TextUtils.isEmpty(tel)){
         mView.loadempe();
        }
        baseApi.login(tel, password)
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(new BaseObserver<LoginBean>() {
                    @Override
                    public void onSuccess(LoginBean loginBean) {
                        mView.loadlogin(loginBean);
                    }

                    @Override
                    public void onFail(Throwable e) {
                        mView.showFaild();
                    }
                });
    }


}
